<template>
	<view>
		<!-- 地址 -->
		<view class="address">
			<!-- 按钮 -->
			<button @click="choose" v-if="Object.keys(address).length === 0" type="primary" size="mini">请选择收货地址</button>
			<!-- 内容 -->
			<view class="content" v-else>
				<view class="top">
					<view class="name">
						收货人：{{address.userName}}
					</view>
					<view class="phone">
						<text>电话： {{address.telNumber}}</text>
						<uni-icons type="right" @click="choose"></uni-icons>
					</view>
				</view>
				<view class="bottom">
					收货地址：{{dzStr}}
				</view>
			</view>
			<image class="border" src="/static/images/border.png" mode=""></image>
		</view>
	</view>
</template>

<script>
	import {mapMutations, mapState, mapGetters} from 'vuex'
	export default {
		name: "my-address",
		data() {
			return {
				
			}
		},
		computed: {
			...mapState('m_user', ['address']),
			...mapGetters('m_user', ['dzStr'])
		},
		methods: {
			...mapMutations('m_user', ['updateAddress']),
			// 选择收货地址
			choose() {
				// 使用微信地址
				uni.chooseAddress({
					success: res => {
						console.log(res)
						// this.address = res
						this.updateAddress(res)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.address {
		position: relative;
		height: 90px;

		button {
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
		}

		.border {
			width: 100%;
			height: 5px;
			position: absolute;
			left: 0;
			bottom: 0;
		}

		.content {
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			font-size: 12px;
			height: 100%;
			box-sizing: border-box;
			padding: 10px 6px;

			.top {
				display: flex;
				justify-content: space-between;
			}
		}

	}
</style>
